/**
 * 
 */
package controller;

import game.AssetManager;

import java.awt.Point;

import menus.Chat;
import menus.MapSelection;
import menus.MainMenu;
import connectors.Connection;
import connectors.Delegator;

/**
 * @author Lucas 'Mezmor' Pfister
 *
 */
public class Controller {
	
	public Connection conn;
	public enum GameState {
		ESTABLISHING_CONNECTION,
		MAP_SELECTION,
		COLOR_SELECTION,
		RED_PLAYS,
		BLUE_PLAYS,
		POST_GAME
	}
	public GameState state;
	public AssetManager assets;
	
	
	public Controller(){
		state = GameState.ESTABLISHING_CONNECTION;
		assets = new AssetManager(); // Loads assets
	}
	
	public static void main(String[] args) {
		Controller controller = new Controller();
		
		MainMenu mainMenu = new MainMenu(controller);
		mainMenu.setVisible(true);
		
		Chat chat = null;
		MapSelection mapSelector = null;
		
		while(true){
			// Here we handle the GameState
			switch(controller.state) {
				case ESTABLISHING_CONNECTION:
					break;
				case MAP_SELECTION:
					if(mapSelector == null){
						mapSelector = new MapSelection(controller);
						//mapSelector.pack();
						mapSelector.setVisible(true);
					}
					if(chat == null){
						mainMenu.destroy();
						chat = new Chat(controller);
						Point chatLocation = mapSelector.getLocation();
						chatLocation.x += (mapSelector.getWidth() + 10);
						chat.setLocation(chatLocation);
						chat.setVisible(true);
						new Delegator(controller, chat, mapSelector); // Create the Data Delegator. GOD I HATE STATIC METHODS
					}
					break;
				case COLOR_SELECTION:
					break;
				default:
					break;
			}
			
			// Here we print it out because we're too lazy to write real test cases.
			//System.out.println(controller.state.toString());
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}